package cn.agiledata.bank.wap.dao;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.SessionFactory;

import cn.agiledata.bank.common.dao.HqlPageListTemplate;
import cn.agiledata.bank.common.util.DateUtil;
import cn.agiledata.bank.common.util.StringUtil;
import cn.agiledata.bank.wap.bean.HisAccountQueryBean;
import com.vnv.infrastructure.exception.IPBException;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class HisAccountQueryPageListPage extends HqlPageListTemplate {
	private HisAccountQueryBean bean;
	
	public HisAccountQueryPageListPage(HisAccountQueryBean bean) {

			this.setSessionFactory(
					(SessionFactory)IPBAppFactory.getObj("sessionFactory"));

		this.bean = bean;
	}
	
	public String getHql() {
		// TODO Auto-generated method stub
		String hSql = " select new cn.agiledata.bank.myspace.bean.AccountQueryBean(a, t) from "
			+ " Transaction t ,Account a "
			+ "where (t.credit.account.id=a.id or t.debit.account.id=a.id ) ";
		hSql += " and a.id=:id";
		hSql += " and (t.credit.id=:subAcountId or t.debit.id=:subAcountId)";
		if(bean.getStartDate() != null) {
			hSql += " and t.updateTime>=:startDate ";
		}
		if(bean.getEndDate() != null) {
			hSql += " and t.updateTime<=:endDate ";
		}
		hSql += " order by t.updateTime desc";
		return hSql;
	}

	public String getPageRecord() {
		// TODO Auto-generated method stub
		return "1";
	}

	public Map getParams() {
		Map map = new HashMap();
		if(!StringUtil.isStrEmpty(bean.getAccountId())) {
			map.put("id",new Long(bean.getAccountId()));
		}
		if(!StringUtil.isStrEmpty(bean.getSubAccountId())) {
			map.put("subAcountId",new Long(bean.getSubAccountId()));
		}
		if(bean.getStartDate() != null) {
			map.put("startDate",bean.getStartDate());
		}
		if(bean.getEndDate() != null) {
			map.put("endDate",bean.getEndDate());
		}
		// TODO Auto-generated method stub
		return map;
	}

	public String getStartPage() {
		// TODO Auto-generated method stub
		return bean.getStartPage();
	}

}
